/*package com.utils.spring;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.kyhd.mogen.controller.model.MogenRequest;
import com.kyhd.mogen.controller.model.MogenResponse;
import com.kyhd.mogen.controller.model.MogenResponse.MogenItem;
import com.kyhd.mogen.controller.model.MogenResponse.TotalProperty;
import com.kyhd.mogen.dao.model.BaseInfo;
import com.kyhd.mogen.dao.model.CustomerInvoice;
import com.kyhd.mogen.dao.model.MediaInfo;
import com.kyhd.mogen.dao.model.MediaInvoice;
import com.kyhd.mogen.util.Constant;
import com.kyhd.mogen.util.MathUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class MogenService {
	
	@Autowired
	BaseInfoService baseInfoService;
	@Autowired
	CustomerInvoiceService customerInvoiceService;
	@Autowired
	MediaInvoiceService mediaInvoiceService;
	@Autowired
	MediaInfoService mediaInfoService;
	@Autowired
	@Qualifier("entityManager")
	EntityManager entityManager;

	public MogenResponse search(MogenRequest request) {
		
		MogenResponse response = new MogenResponse();
		TotalProperty totalProperty = new TotalProperty();
		Date settleSDate = null;
		Date settleEDate = null;
		try {
			settleSDate = Constant.formatDateMonth(request.getSettlementSDate());
			settleEDate = Constant.formatDateMonth(request.getSettlementEDate());
		} catch (Exception e) {
			response.setState(Constant.API_STATUS_FAILED);
			response.setMsg("请选择正确的日期格式");
			return response;
		}
		
		StringBuilder select = new StringBuilder("select ");
		
		StringBuilder column = new StringBuilder("");
		column.append(" left(b.settlement_date,7) settlement_date, b.id, b.advertiser, b.settlement_mode, b.product bproduct, ");
		column.append(" b.belong_backstage, b.account, b.media_open_name, b.media_settlement_name, b.channel_name, ");
		column.append(" b.sales, b.owner_body, b.receive_refund_attribute, b.customer_payment_name, b.customer_settlement_data, ");
		column.append(" b.access_price, b.consume, b.customer_rebate_attribute, b.customer_rebate_describe, b.customer_receive_refund_date, ");
		column.append(" b.customer_receive_amount, b.customer_official_amount, b.customer_receive_balance, b.customer_official_balance, b.customer_refund_amount, ");
		column.append(" b.customer_bank_recive_refund_no, b.tax_margin, b.remark, b.operator, date_format(b.lastModifyTime, '%Y-%m-%d %H:%i:%s') lastModifyTime, ");
		column.append(" ci.state cistate, ci.no cino, ci.date cidate, ci.type citype, ci.content cicontent, ");
		column.append(" ci.product ciproduct, ci.amount ciamount, ci.tax citax, ci.price_tax_total ciprice_tax_total, ");
		column.append(" m.pay_backstage_date, ");
		column.append(" m.media_rebate_attribute, m.media_rebate, m.channel_settlement_data, m.release_price, m.payment_amount, ");
		column.append(" m.official_amount, m.refund_amount, m.bank_recive_refund_no,  ");
		column.append(" mi.state mistate, mi.no mino, ");
		column.append(" mi.date midate, mi.purchase, mi.company, mi.type mitype, mi.content micontent,  ");
		column.append(" mi.product miproduct, mi.amount miamount, mi.tax mitax, mi.price_tax_total miprice_tax_total ");
		
		StringBuilder columnTotal = new StringBuilder("");
		columnTotal.append(" sum(b.consume), ");
		columnTotal.append(" sum(b.customer_receive_amount), sum(b.customer_official_amount), sum(b.customer_receive_balance), sum( b.customer_official_balance), sum(b.customer_refund_amount), ");
		columnTotal.append(" sum(ci.amount), sum(ci.tax), sum(ci.price_tax_total), sum(m.payment_amount), sum(m.official_amount), ");
		columnTotal.append(" sum(m.refund_amount), sum(mi.amount), sum(mi.tax), sum( mi.price_tax_total), sum(b.tax_margin) ");
		
		StringBuilder from = new StringBuilder("");
		from.append(" from base_info b ");
		from.append(" left join customer_invoice ci on b.id=ci.base_id ");
		from.append(" left join media_info m on b.id=m.base_id ");
		from.append(" left join media_invoice mi on b.id=mi.base_id ");
		from.append(" where 1=1 and b.deleted=0 ");
		
		StringBuilder where = new StringBuilder("");
		if(request.getSettlementSDate()!=null&&request.getSettlementEDate()!=null) {
			where.append(" and ( Date(b.settlement_date) >=?1 and Date(b.settlement_date)<=?2 ) ");	
		}
		if(StringUtil.isNotBlank(request.getAdvertiser())) {
			where.append(" and b.advertiser like concat('%',?3,'%') ");
		}
		if(request.getSettlementMode()>0) {
			where.append(" and b.settlement_mode = ?4 ");
		}
		if(StringUtil.isNotBlank(request.getProduct())) {
			where.append(" and b.product like concat('%',?5,'%') ");
		}
		if(StringUtil.isNotBlank(request.getMediaOpenName())) {
			where.append(" and b.media_open_name like concat('%',?6,'%') ");
		}
		if(StringUtil.isNotBlank(request.getMediaSettlementName())) {
			where.append(" and b.media_settlement_name like concat('%',?7,'%') ");
		}
		if(StringUtil.isNotBlank(request.getChannelName())) {
			where.append(" and b.channel_name like concat('%',?8,'%') ");
		}
		if(request.getReceiveRefundAttribute()>0) {
			where.append(" and b.receive_refund_attribute = ?9 ");
		}
		if(StringUtil.isNotBlank(request.getCustomerPaymentName())) {
			where.append(" and b.customer_payment_name like concat('%',?10,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerReceiveAmount())) {
			where.append(" and b.customer_receive_amount like concat('%',?11,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerOfficialAmount())) {
			where.append(" and b.customer_official_amount like concat('%',?12,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerReceiveBalance())) {
			where.append(" and b.customer_receive_balance like concat('%',?13,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerOfficialBalance())) {
			where.append(" and b.customer_official_balance like concat('%',?14,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerRefundAmount())) {
			where.append(" and b.customer_refund_amount like concat('%',?15,'%') ");
		}
		if(StringUtil.isNotBlank(request.getCustomerBankReciveRefundNo())) {
			where.append(" and b.customer_bank_recive_refund_no like concat('%',?16,'%') ");
		}
		if(request.getCustomerInvoiceState()>0) {
			where.append(" and ci.state = ?17 ");
		}
		if(StringUtil.isNotBlank(request.getCustomerInvoiceNo())) {
			where.append(" and ci.no like concat('%',?18,'%') ");
		}
		if(request.getCustomerInvoiceType()>0) {
			where.append(" and ci.type = ?19 ");
		}
		if(StringUtil.isNotBlank(request.getCustomerPriceTaxTotal())) {
			where.append(" and ci.price_tax_total like concat('%',?20,'%') ");
		}
		if(StringUtil.isNotBlank(request.getPaymentAmount())) {
			where.append(" and m.payment_amount like concat('%',?21,'%') ");
		}
		if(StringUtil.isNotBlank(request.getOfficialAmount())) {
			where.append(" and m.official_amount like concat('%',?22,'%') ");
		}
		if(StringUtil.isNotBlank(request.getRefundAmount())) {
			where.append(" and m.refund_amount like concat('%',?23,'%') ");
		}
		if(request.getMediaInvoiceState()>0) {
			where.append(" and mi.state = ?24 ");
		}
		if(request.getId()>0) {
			where.append(" and b.id = ?25 ");
		}
		
		StringBuilder order = new StringBuilder("");
		order.append(" order by b.settlement_date desc, b.lastModifyTime desc");

		List<MogenItem> mList = new ArrayList<MogenItem>();
		
		List<Object[]>  list = null;
		List<Object[]> totalList = null;
		Object count = null;
		
		String sqlLimit = null;
		if(request.isAll()==true) {
			sqlLimit = select.toString()+column.toString()+from.toString()+where.toString()+order.toString();
		}else {
			sqlLimit = "select lt.* from ( "
					+select.toString()+column.toString()+from.toString()+where.toString()+order.toString()
					+" ) lt order by lt.settlement_date desc, lt.lastModifyTime desc limit  "
					+(request.getOffset()-1)*request.getLimit()+", "+request.getLimit()+" ";
		}

		
		String sqlTotal = select.toString()+columnTotal.toString()+from.toString()+where.toString();
		
		String sqlCount = "select count(1) from ("+select.toString()+column.toString()+from.toString()+where.toString()+") bcm";
				
//		log.info("sqlLimit:"+sqlLimit);
//		log.info("sqlTotal:"+sqlTotal);
//		log.info("sqlCount:"+sqlCount);
		try {

			Query queryCount = this.entityManager.createNativeQuery(sqlCount.toString());
			queryCount = setParam(request, queryCount,settleSDate, settleEDate);
			count = queryCount.getSingleResult();
			
			Query query = this.entityManager.createNativeQuery(sqlLimit.toString());
			query = setParam(request, query,settleSDate, settleEDate);
			list = query.getResultList();
			
			Query queryTotal = this.entityManager.createNativeQuery(sqlTotal.toString());
			query = setParam(request, queryTotal,settleSDate, settleEDate);
			totalList = queryTotal.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			return response;
		}
		for (Object[] m : list) {
			MogenItem mt = new MogenItem();
			setMogenItem(m, mt);
			mList.add(mt);
		}
		
		for (Object[] objects : totalList) {
			totalProperty.setConsume(MathUtil.decimalFormatString(objects[0]==null?null:objects[0].toString()));
			totalProperty.setCustomerInvoiceAmount(MathUtil.decimalFormatString(objects[6]==null?null:objects[6].toString()));
			totalProperty.setCustomerInvoiceTax(MathUtil.decimalFormatString(objects[7]==null?null:objects[7].toString()));
			totalProperty.setCustomerOfficialAmount(MathUtil.decimalFormatString(objects[2]==null?null:objects[2].toString()));
			totalProperty.setCustomerOfficialBalance(MathUtil.decimalFormatString(objects[4]==null?null:objects[4].toString()));
			totalProperty.setCustomerPriceTaxTotal(MathUtil.decimalFormatString(objects[8]==null?null:objects[8].toString()));
			totalProperty.setCustomerReceiveAmount(MathUtil.decimalFormatString(objects[1]==null?null:objects[1].toString()));
			totalProperty.setCustomerReceiveBalance(MathUtil.decimalFormatString(objects[3]==null?null:objects[3].toString()));
			totalProperty.setCustomerRefundAmount(MathUtil.decimalFormatString(objects[5]==null?null:objects[5].toString()));
			totalProperty.setMediaInvoiceAmount(MathUtil.decimalFormatString(objects[12]==null?null:objects[12].toString()));
			totalProperty.setMediaInvoicePriceTaxTotal(MathUtil.decimalFormatString(objects[14]==null?null:objects[14].toString()));
			totalProperty.setMediaInvoiceTax(MathUtil.decimalFormatString(objects[13]==null?null:objects[13].toString()));
			totalProperty.setOfficialAmount(MathUtil.decimalFormatString(objects[10]==null?null:objects[10].toString()));
			totalProperty.setPaymentAmount(MathUtil.decimalFormatString(objects[9]==null?null:objects[9].toString()));
			totalProperty.setRefundAmount(MathUtil.decimalFormatString(objects[11]==null?null:objects[11].toString()));
			totalProperty.setTaxMargin(MathUtil.decimalFormatString(objects[15]==null?null:objects[15].toString()));
		}
		response.setTotalProperty(totalProperty);
		response.setList(mList);
		response.setTotal(Long.valueOf(count.toString()));
		
        return response;
	}

	public void setMogenItem(Object[] m, MogenItem mt) {
		mt.setAccessPrice(MathUtil.decimalFormatString(m[15]==null?null:m[15].toString()));
		mt.setAccount(m[6]==null?null:m[6].toString());
		mt.setAdvertiser(m[2]==null?null:m[2].toString());
		mt.setBankReciveReundNo(m[47]==null?null:m[47].toString());
		mt.setBelongBackstage(m[5]==null?null:m[5].toString());
		mt.setChannelName(m[9]==null?null:m[9].toString());
		mt.setChannelSettlementData(m[42]==null?null:m[42].toString());
		mt.setConsume(MathUtil.decimalFormatString(m[16]==null?null:m[16].toString()));
		mt.setCustomerBankReciveRefundNo(m[25]==null?null:m[25].toString());
		mt.setCustomerInvoiceAmount(MathUtil.decimalFormatString(m[36]==null?null:m[36].toString()));
		mt.setCustomerInvoiceContent(m[34]==null?null:m[34].toString());
		mt.setCustomerInvoiceDate(m[32]==null?null:m[32].toString());
		mt.setCustomerInvoiceNo(m[31]==null?null:m[31].toString());
		mt.setCustomerInvoiceProduct(m[35]==null?null:m[35].toString());
		mt.setCustomerInvoiceState(Constant.CustomerInvoiceState.getMsg(Integer.valueOf(m[30]==null?"0":m[30].toString())));
		mt.setCustomerInvoiceTax(MathUtil.decimalFormatString(m[37]==null?null:m[37].toString()));
		mt.setCustomerInvoiceType(Constant.CustomerInvoiceType.getMsgStr(Integer.valueOf(m[33]==null?"0":m[33].toString())));
		mt.setCustomerOfficialAmount(MathUtil.decimalFormatString(m[21]==null?null:m[21].toString()));
		mt.setCustomerOfficialBalance(MathUtil.decimalFormatString(m[23]==null?null:m[23].toString()));
		mt.setCustomerPaymentName(m[13]==null?null:m[13].toString());
		mt.setCustomerPriceTaxTotal(MathUtil.decimalFormatString(m[38]==null?null:m[38].toString()));
		mt.setCustomerRebateAttribute(m[17]==null?null:m[17].toString());
		mt.setCustomerRebateDescribe(m[18]==null?null:m[18].toString());
		mt.setCustomerReceiveAmount(MathUtil.decimalFormatString(m[20]==null?null:m[20].toString()));
		mt.setCustomerReceiveBalance(MathUtil.decimalFormatString(m[22]==null?null:m[22].toString()));
		mt.setCustomerReceiveRefundDate(m[19]==null?null:m[19].toString());
		mt.setCustomerRefundAmount(MathUtil.decimalFormatString(m[24]==null?null:m[24].toString()));
		mt.setCustomerSettlementData(m[14]==null?null:m[14].toString());
		mt.setId(Long.valueOf(m[1]==null?null:m[1].toString()));
		mt.setLastModifyTime(m[29]==null?null:Constant.formatDatetime(m[29].toString()));
		mt.setMediaInvoiceAmount(MathUtil.decimalFormatString(m[56]==null?null:m[56].toString()));
		mt.setMediaInvoiceCompany(m[52]==null?null:m[52].toString());
		mt.setMediaInvoiceContent(m[54]==null?null:m[54].toString());
		mt.setMediaInvoiceDate(m[50]==null?null:m[50].toString());
		mt.setMediaInvoiceNo(m[49]==null?null:m[49].toString());
		mt.setMediaInvoicePriceTaxTotal(MathUtil.decimalFormatString(m[58]==null?null:m[58].toString()));
		mt.setMediaInvoiceProduct(m[55]==null?null:m[55].toString());
		mt.setMediaInvoicePurchase(m[51]==null?null:m[51].toString());
		mt.setMediaInvoiceState(Constant.MediaInvoiceState.getMsg(Integer.valueOf(m[48]==null?"0":m[48].toString())));
		mt.setMediaInvoiceTax(MathUtil.decimalFormatString(m[57]==null?"0":m[57].toString()));
		mt.setMediaInvoiceType(Constant.MediaInvoiceType.getMsgStr(Integer.valueOf(m[53]==null?"0":m[53].toString())));
		mt.setMediaOpenName(m[7]==null?null:m[7].toString());
		mt.setMediaRebate(m[41]==null?null:m[41].toString());
		mt.setMediaRebateAttribute(m[40]==null?null:m[40].toString());
		mt.setMediaSettlementName(m[8]==null?null:m[8].toString());
		mt.setOfficialAmount(MathUtil.decimalFormatString(m[45]==null?null:m[45].toString()));
		mt.setOperator(m[28]==null?null:m[28].toString());
		mt.setOwnerBody(m[11]==null?null:m[11].toString());
		mt.setPayBckstageDate(m[39]==null?null:m[39].toString());
		mt.setPaymentAmount(MathUtil.decimalFormatString(m[44]==null?null:m[44].toString()));
		mt.setProduct(m[4]==null?null:m[4].toString());
		mt.setReceiveRefundAttribute(Constant.ReceiveRefundAttribute.getMsg(Integer.valueOf(m[12]==null?"0":m[12].toString())));
		mt.setRefundAmount(MathUtil.decimalFormatString(m[46]==null?null:m[46].toString()));
		mt.setReleasePrice(MathUtil.decimalFormatString(m[43]==null?null:m[43].toString()));
		mt.setRemark(m[27]==null?null:m[27].toString());
		mt.setSales(m[10]==null?null:m[10].toString());
		mt.setSettlementDate(m[0]==null?null:m[0].toString());
		mt.setSettlementMode(Constant.SettlementMode.getMsg(Integer.valueOf(m[3]==null?"0":m[3].toString())).toUpperCase().replace("AC", "A"+Constant.SETTLEMENT_MODE_SYMBOL+"C"));
		mt.setTaxMargin(MathUtil.decimalFormatString(m[26]==null?null:m[26].toString()));
	}
	
	public Query setParam(MogenRequest request, Query query, Date settleSDate, Date settleEDate) {
		if(request.getSettlementSDate()!=null&&request.getSettlementEDate()!=null) {
			query.setParameter(1, settleSDate);
			query.setParameter(2, settleEDate);				
		}
		if(StringUtil.isNotBlank(request.getAdvertiser())) {
			query.setParameter(3, request.getAdvertiser());
		}
		if(request.getSettlementMode()>0) {
			query.setParameter(4, request.getSettlementMode());
		}
		if(StringUtil.isNotBlank(request.getProduct())) {
			query.setParameter(5, request.getProduct());
		}
		if(StringUtil.isNotBlank(request.getMediaOpenName())) {
			query.setParameter(6, request.getMediaOpenName());
		}
		if(StringUtil.isNotBlank(request.getMediaSettlementName())) {
			query.setParameter(7, request.getMediaSettlementName());
		}
		if(StringUtil.isNotBlank(request.getChannelName())) {
			query.setParameter(8, request.getChannelName());
		}
		if(request.getReceiveRefundAttribute()>0) {
			query.setParameter(9, request.getReceiveRefundAttribute());
		}
		if(StringUtil.isNotBlank(request.getCustomerPaymentName())) {
			query.setParameter(10, request.getCustomerPaymentName());
		}
		if(StringUtil.isNotBlank(request.getCustomerReceiveAmount())) {
			query.setParameter(11, Constant.delZero(request.getCustomerReceiveAmount()));
		}
		if(StringUtil.isNotBlank(request.getCustomerOfficialAmount())) {
			query.setParameter(12, Constant.delZero(request.getCustomerOfficialAmount()));
		}
		if(StringUtil.isNotBlank(request.getCustomerReceiveBalance())) {
			query.setParameter(13, Constant.delZero(request.getCustomerReceiveBalance()));
		}
		if(StringUtil.isNotBlank(request.getCustomerOfficialBalance())) {
			query.setParameter(14, Constant.delZero(request.getCustomerOfficialBalance()));
		}
		if(StringUtil.isNotBlank(request.getCustomerRefundAmount())) {
			query.setParameter(15, Constant.delZero(request.getCustomerRefundAmount()));
		}
		if(StringUtil.isNotBlank(request.getCustomerBankReciveRefundNo())) {
			query.setParameter(16, request.getCustomerBankReciveRefundNo());
		}
		if(request.getCustomerInvoiceState()>0) {
			query.setParameter(17, request.getCustomerInvoiceState());
		}
		if(StringUtil.isNotBlank(request.getCustomerInvoiceNo())) {
			query.setParameter(18, request.getCustomerInvoiceNo());
		}
		if(request.getCustomerInvoiceType()>0) {
			query.setParameter(19, request.getCustomerInvoiceType());
		}
		if(StringUtil.isNotBlank(request.getCustomerPriceTaxTotal())) {
			query.setParameter(20, Constant.delZero(request.getCustomerPriceTaxTotal()));
		}
		if(StringUtil.isNotBlank(request.getPaymentAmount())) {
			query.setParameter(21, Constant.delZero(request.getPaymentAmount()));
		}
		if(StringUtil.isNotBlank(request.getOfficialAmount())) {
			query.setParameter(22, Constant.delZero(request.getOfficialAmount()));
		}
		if(StringUtil.isNotBlank(request.getRefundAmount())) {
			query.setParameter(23, Constant.delZero(request.getRefundAmount()));
		}
		if(request.getMediaInvoiceState()>0) {
			query.setParameter(24, request.getMediaInvoiceState());
		}
		if(request.getId()>0) {
			query.setParameter(25, request.getId());
		}
		return query;
	}
	
	*//**
	 * 根据id查询
	 * @param id
	 * @return
	 *//*
	public MogenResponse QueryById(long id) {
		MogenResponse response = new MogenResponse();
		MogenItem mi = new MogenItem();
		
		StringBuilder select = new StringBuilder("select ");
		
		StringBuilder column = new StringBuilder("");
		column.append(" left(b.settlement_date,7) settlement_date, b.id, b.advertiser, b.settlement_mode, b.product bproduct, ");
		column.append(" b.belong_backstage, b.account, b.media_open_name, b.media_settlement_name, b.channel_name, ");
		column.append(" b.sales, b.owner_body, b.receive_refund_attribute, b.customer_payment_name, b.customer_settlement_data, ");
		column.append(" b.access_price, b.consume, b.customer_rebate_attribute, b.customer_rebate_describe, b.customer_receive_refund_date, ");
		column.append(" b.customer_receive_amount, b.customer_official_amount, b.customer_receive_balance, b.customer_official_balance, b.customer_refund_amount, ");
		column.append(" b.customer_bank_recive_refund_no, b.tax_margin, b.remark, b.operator, date_format(b.lastModifyTime, '%Y-%m-%d %H:%i:%s') lastModifyTime, ");
		column.append(" ci.state cistate, ci.no cino, ci.date cidate, ci.type citype, ci.content cicontent, ");
		column.append(" ci.product ciproduct, ci.amount ciamount, ci.tax citax, ci.price_tax_total ciprice_tax_total, ");
		column.append(" m.pay_backstage_date, ");
		column.append(" m.media_rebate_attribute, m.media_rebate, m.channel_settlement_data, m.release_price, m.payment_amount, ");
		column.append(" m.official_amount, m.refund_amount, m.bank_recive_refund_no,  ");
		column.append(" mi.state mistate, mi.no mino, ");
		column.append(" mi.date midate, mi.purchase, mi.company, mi.type mitype, mi.content micontent,  ");
		column.append(" mi.product miproduct, mi.amount miamount, mi.tax mitax, mi.price_tax_total miprice_tax_total ");

		StringBuilder from = new StringBuilder("");
		from.append(" from base_info b ");
		from.append(" left join customer_invoice ci on b.id=ci.base_id ");
		from.append(" left join media_info m on b.id=m.base_id ");
		from.append(" left join media_invoice mi on b.id=mi.base_id ");
		from.append(" where 1=1 and b.deleted=0 ");
		
		StringBuilder where = new StringBuilder("");
		if(id>0) {
			where.append(" and b.id = ?1 ");
		}

		List<MogenItem> mList = new ArrayList<MogenItem>();
		
		List<Object[]> list = null;
		String sqlLimit = select.toString()+column.toString()+from.toString()+where.toString();
				
		try {
			Query query = this.entityManager.createNativeQuery(sqlLimit.toString());
			if(id>0) {
				query.setParameter(1, id);
			}
			list = query.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			return response;
		}
		
		for (Object[] m : list) {
			MogenItem mt = new MogenItem();
			setMogenItem(m, mt);
			mList.add(mt);
//			log.info("MogenItem:{}", mt);
		}
		response.setList(mList);
		return response;
	}
	
	*//**
	 * 编辑
	 * @param request
	 * @param operator
	 * @return
	 *//*
	public JSONObject edit(MogenItem request, String operator) {
		JSONObject ret = new JSONObject();
		try {
			BaseInfo bi = new BaseInfo();
			bi = this.baseInfoService.getById(request.getId());
			bi = this.baseInfoService.setBean(bi, request, operator, true);
			bi = this.baseInfoService.update(bi);
			
			CustomerInvoice ci = new CustomerInvoice();
			ci = this.customerInvoiceService.getByBaseId(request.getId());
			ci = this.customerInvoiceService.setBean(ci, bi, request, operator, true);
			ci = this.customerInvoiceService.update(ci);
			
			MediaInfo m = new MediaInfo();
			m = this.mediaInfoService.getByBaseId(request.getId());
			m = this.mediaInfoService.setBean(m, bi, request, operator, true);
			m = this.mediaInfoService.update(m);
			
			MediaInvoice mi = new MediaInvoice();
			mi = this.mediaInvoiceService.getByBaseId(request.getId());
			mi = this.mediaInvoiceService.setBean(mi, bi, request, operator, true);
			mi = this.mediaInvoiceService.update(mi);
		} catch (Exception e) {
			e.printStackTrace();
			ret.put("state", Constant.API_STATUS_FAILED);
			ret.put("msg", "编辑保存异常："+e.getMessage());
		}
		return ret;
	}

	*//**
	 * 删除
	 * @param ids
	 * @param operator
	 *//*
	public void deleteByIds(List<Long> ids, String operator) {
		this.baseInfoService.deleteByLongIds(ids, operator);
		String idStr = "";
		for (Long id : ids) {
			idStr = idStr+id+",";
		}
		if(idStr.endsWith(",")) {
			idStr = idStr.substring(0, idStr.lastIndexOf(","));
		}
		log.info("delete ids:{}",idStr);
		this.baseInfoService.deleteByIds(idStr, operator);
	}

	*//**
	 * 删除
	 * @param id
	 * @param operator
	 *//*
	public void deleteById(Long id, String operator) {
		this.baseInfoService.deleteById(id, operator);
	}
	
	*//**
	 * 判重
	 * @param item
	 * @return
	 *//*
	public boolean exist(MogenItem item) {
		boolean exist = false;
		BaseInfo bi = this.check(item);
		if(bi!=null) 
			exist = true; 
		return exist;
	}
	
	public BaseInfo check(MogenItem item) {
		String settlementDate = item.getSettlementDate().substring(0,7);
		int settlementMode = Constant.SettlementMode.getType(item.getSettlementMode().toUpperCase().replace(Constant.SETTLEMENT_MODE_SYMBOL, ""));
		String product = item.getProduct();
		String belongBackstage = item.getBelongBackstage();
		int receiveRefundAttribute = Constant.ReceiveRefundAttribute.getType(item.getReceiveRefundAttribute());
		String customerPaymentName = item.getCustomerPaymentName();
		
		BaseInfo bi = this.baseInfoService.check(settlementDate, settlementMode, product, belongBackstage, receiveRefundAttribute, customerPaymentName);
		return bi;
	}

	*//**
	 * 更新保存
	 * @param item
	 * @param operator
	 * @param operateType
	 * @param isUpdate
	 * @return
	 * @throws Exception 
	 *//*
	public boolean save(MogenItem item, String operator, int operateType, boolean isUpdate) throws Exception {
		boolean result = true;
		try {
			BaseInfo bi = new BaseInfo();
			CustomerInvoice ci = new CustomerInvoice();
			MediaInfo m = new MediaInfo();
			MediaInvoice mi = new MediaInvoice();
			if (item.getId() > 0) {
				bi = this.baseInfoService.getById(item.getId());
				if(bi==null) 
					throw new Exception(Constant.ImportMsg.getMsg(13));
				bi = this.baseInfoService.setBean(bi, item, operator, isUpdate);
				bi = this.baseInfoService.update(bi);

				ci = this.customerInvoiceService.getByBaseId(item.getId());
				ci = this.customerInvoiceService.setBean(ci, bi, item, operator, isUpdate);
				ci = this.customerInvoiceService.update(ci);

				m = this.mediaInfoService.getByBaseId(item.getId());
				m = this.mediaInfoService.setBean(m, bi, item, operator, isUpdate);
				m = this.mediaInfoService.update(m);

				mi = this.mediaInvoiceService.getByBaseId(item.getId());
				mi = this.mediaInvoiceService.setBean(mi, bi, item, operator, isUpdate);
				mi = this.mediaInvoiceService.update(mi);
			} else {
				bi = this.baseInfoService.setBean(bi, item, operator, isUpdate);
				bi = this.baseInfoService.save(bi);

				ci = this.customerInvoiceService.setBean(ci, bi, item, operator, isUpdate);
				ci = this.customerInvoiceService.save(ci);

				m = this.mediaInfoService.setBean(m, bi, item, operator, isUpdate);
				m = this.mediaInfoService.save(m);

				mi = this.mediaInvoiceService.setBean(mi, bi, item, operator, isUpdate);
				mi = this.mediaInvoiceService.save(mi);
			}
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
			throw e;
		}

		return result;
	}

}
*/